package cn.wolfcode.wolf2w.business.service.Impl;


import cn.wolfcode.wolf2w.business.api.domain.TaDestinationEs;
import cn.wolfcode.wolf2w.business.repository.TaDestinationEsRepository;
import cn.wolfcode.wolf2w.business.service.ITaDestinationEsService;
import cn.wolfcode.wolf2w.common.core.constant.SecurityConstants;
import cn.wolfcode.wolf2w.common.core.domain.R;
import cn.wolfcode.wolf2w.common.core.utils.bean.BeanUtils;
import cn.wolfcode.wolf2w.destination.RemoteDestinationServer;
import cn.wolfcode.wolf2w.destination.entity.TaDestination;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class TaDestinationEsServiceImpl implements ITaDestinationEsService {


    @Autowired
    private TaDestinationEsRepository repository;
    @Autowired
    private RemoteDestinationServer remoteDestinationServer;

    @Override
    public void initTaDestinationEs() {
        R<List<TaDestination>> r = remoteDestinationServer.list(SecurityConstants.INNER);
        List<TaDestinationEs> esList = new ArrayList<>();
        List<TaDestination> list = r.getData();
        for (TaDestination taDestination : list) {
            TaDestinationEs es = new TaDestinationEs();
            BeanUtils.copyProperties(taDestination,es);
            esList.add(es);
        }
        repository.saveAll(esList);
    }
}
